
#!/bin/bash

CURRENT_DIRECTORY=`pwd`
export LIB_ROOT_DIR=${CURRENT_DIRECTORY}/libs
export INSTALL_DIR=${LIB_ROOT_DIR}/linux
export SOURCE_DIR=${LIB_ROOT_DIR}/sources_linux
export BUILD_DIR=${LIB_ROOT_DIR}/build_linux

rm -fr ${BUILD_DIR}
mkdir -p ${LIB_ROOT_DIR}
mkdir -p ${INSTALL_DIR}
mkdir -p ${SOURCE_DIR}
mkdir -p ${BUILD_DIR}

echo ${CURRENT_DIRECTORY}

sudo apt install pkg-config
sudo apt install libtool
# =================================Install Lua===================================
LIB_VERSION=5.4.4
LIB_NAME=lua-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

# 安装目录不存在则进行安装
if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
            wget http://www.lua.org/ftp/${LIB_NAME}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    cd ${LIB_SRC_DIR}

	make clean
    make 
    make local 
	mkdir -p ${LIB_INSTALL_DIR}
    mv ${LIB_SRC_DIR}/install/include ${LIB_INSTALL_DIR}
    mv ${LIB_SRC_DIR}/install/lib ${LIB_INSTALL_DIR}
    cd -
fi


# =================================Install LuaBridge===================================
LIB_VERSION=2.6
LIB_NAME=LuaBridge-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
            wget https://ghproxy.com/https://github.com/vinniefalco/LuaBridge/archive/refs/tags/${LIB_VERSION}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    mkdir -p ${LIB_INSTALL_DIR}/include
    cp -fr ${LIB_SRC_DIR}/Source/LuaBridge ${LIB_INSTALL_DIR}/include/LuaBridge
fi


# =================================Install SDL2===================================
LIB_VERSION=2.0.22
LIB_NAME=SDL2-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
            wget https://ghproxy.com/https://github.com/libsdl-org/SDL/releases/download/release-${LIB_VERSION}/${LIB_NAME}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    cd ${LIB_SRC_DIR}
	#make clean
    ./configure --prefix=${LIB_INSTALL_DIR}
    make
    make install
    cd -
fi

# =================================Install Expat===================================
LIB_VERSION=2.4.8
LIB_NAME=expat-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
	if [ ! -d ${LIB_SRC_DIR} ]; then
		rm -fr ${SOURCE_DIR}/SDL_net-release-${LIB_VERSION}
		if [ -f ${LIB_SRC_TAR_GZ} ]; then
			tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
		else
			wget https://ghproxy.com/https://github.com/libexpat/libexpat/releases/download/R_2_4_8/${LIB_NAME}.tar.gz -O ${LIB_SRC_TAR_GZ}
			tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
		fi
	fi

	mkdir -p ${LIB_BUILD_DIR}
	cmake -B ${LIB_BUILD_DIR} -S ${LIB_SRC_DIR} \
		-DBUILD_SHARED_LIBS=OFF \
		-DEXPAT_SHARED_LIBS:BOOL=OFF \
		-DEXPAT_WITH_LIBBSD:BOOL=OFF \
		-DEXPAT_MSVC_STATIC_CRT:BOOL=ON \
		-DEXPAT_BUILD_PKGCONFIG:BOOL=OFF \
		-DEXPAT_BUILD_DOCS:BOOL=OFF \
		-DCMAKE_BUILD_TYPE:STRING=Release \
		-DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_DIR}
	cmake --build ${LIB_BUILD_DIR}
	cmake --install ${LIB_BUILD_DIR}
fi

# =================================Install SDL_net===================================
#LIB_VERSION=2.0.1
#LIB_NAME=SDL_net-${LIB_VERSION}
#LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
#LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
#LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
#LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

#if [ ! -d ${LIB_INSTALL_DIR} ]; then
    #if [ ! -d ${LIB_SRC_DIR} ]; then
        #rm -fr ${SOURCE_DIR}/SDL_net-release-${LIB_VERSION}
        #if [ -f ${LIB_SRC_TAR_GZ} ]; then
            #tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
            #mv ${SOURCE_DIR}/SDL_net-release-${LIB_VERSION} ${LIB_SRC_DIR}
        #else
            #wget https://ghproxy.com/https://github.com/libsdl-org/SDL_net/archive/refs/tags/release-${LIB_VERSION}.tar.gz -O ${LIB_SRC_TAR_GZ}
            #tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
            #mv ${SOURCE_DIR}/SDL_net-release-${LIB_VERSION} ${LIB_SRC_DIR}
        #fi
    #fi

    #mkdir -p ${LIB_BUILD_DIR}
    #cmake -B ${LIB_BUILD_DIR} -S ${LIB_SRC_DIR} -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_DIR}
    #cmake --build ${LIB_BUILD_DIR}
    #cmake --install ${LIB_BUILD_DIR}
#fi

# =================================Install libiconv===================================
LIB_VERSION=1.16
LIB_NAME=libiconv-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
            wget https://ftp.gnu.org/pub/gnu/libiconv/${LIB_NAME}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    cd ${LIB_SRC_DIR}
	make clean
    ./configure  --enable-static --enable-shared=no --enable-extra-encodings --without-libiconv-prefix --without-libintl-prefix --prefix=${LIB_INSTALL_DIR} 
    make
    make install
    cd -
fi


# =================================Install libuv===================================
LIB_VERSION=1.44.1
LIB_NAME=libuv-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
            wget https://ghproxy.com/https://github.com/libuv/libuv/archive/refs/tags/v${LIB_VERSION}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    cd ${LIB_SRC_DIR}
	bash autogen.sh
    ./configure  --enable-static --enable-shared=no --prefix=${LIB_INSTALL_DIR} 
    make
    make install
    cd -
fi

# =================================Install openssl===================================
LIB_VERSION=3.0.2
LIB_NAME=openssl-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}
OPENSSL_ROOT_DIR=${LIB_INSTALL_DIR}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
            wget https://www.openssl.org/source/${LIB_NAME}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    cd ${LIB_SRC_DIR}
	make clean
    ./Configure --prefix=${LIB_INSTALL_DIR} 
    make
    make install_dev
	cp -fr ${LIB_INSTALL_DIR}/lib64 ${LIB_INSTALL_DIR}/lib
    cd -
fi


# =================================Install curl===================================
LIB_VERSION=7.82.0
LIB_NAME=curl-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}
CURL_ROOT_DIR=${LIB_INSTALL_DIR}

#rm -fr ${LIB_INSTALL_DIR}
if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
            wget https://curl.se/download/${LIB_NAME}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    cd ${LIB_SRC_DIR}
	make clean
    ./configure --enable-static --enable-shared=no --prefix=${LIB_INSTALL_DIR} --with-openssl=${OPENSSL_ROOT_DIR}
    make
    make install
    cd -
fi


# =================================Install tinyxml2===================================
LIB_VERSION=9.0.0
LIB_NAME=tinyxml2-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
		    wget https://ghproxy.com/https://github.com/leethomason/tinyxml2/archive/refs/tags/${LIB_VERSION}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    mkdir -p ${LIB_BUILD_DIR}
    cd ${LIB_BUILD_DIR}
    cmake -S ${LIB_SRC_DIR} -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_DIR}
    make
    make install 
    cd -
fi


# =================================Install spdlog===================================
LIB_VERSION=1.10.0
LIB_NAME=spdlog-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
            wget https://ghproxy.com/https://github.com/gabime/spdlog/archive/refs/tags/v${LIB_VERSION}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    mkdir -p ${LIB_BUILD_DIR}
    cd ${LIB_BUILD_DIR}
    cmake -S ${LIB_SRC_DIR} -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_DIR}
    make
    make install 
    cd -
fi


# =================================Install CRYPTOPP===================================
#LIB_VERSION=8_6_0
#LIB_NAME=CRYPTOPP_${LIB_VERSION}
#LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
#LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
#LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
#LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

##rm -fr ${LIB_INSTALL_DIR}
#if [ ! -d ${LIB_INSTALL_DIR} ]; then
    #if [ ! -d ${LIB_SRC_DIR} ]; then
        #if [ -f ${LIB_SRC_TAR_GZ} ]; then
            #tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
			#mv ${SOURCE_DIR}/cryptopp-${LIB_NAME} ${LIB_SRC_DIR}
        #else
			#wget https://ghproxy.com/https://github.com/weidai11/cryptopp/archive/refs/tags/${LIB_NAME}.tar.gz -O ${LIB_SRC_TAR_GZ}
            #tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
			#mv ${SOURCE_DIR}/cryptopp-${LIB_NAME} ${LIB_SRC_DIR}
        #fi
    #fi

    #cd ${LIB_SRC_DIR}
	##make clean
    #make install PREFIX=${LIB_INSTALL_DIR}
	#mkdir -p ${LIB_INSTALL_DIR}/lib 
	#cp libcryptopp.a ${LIB_INSTALL_DIR}/lib
    #cd -
#fi

# =================================Install zlib===================================
LIB_VERSION=1.2.12
LIB_NAME=zlib-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}
ZLIB_ROOT_DIR=${LIB_INSTALL_DIR}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
            wget http://zlib.net/${LIB_NAME}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    cd ${LIB_SRC_DIR}
    ./configure  --static --prefix=${LIB_INSTALL_DIR}
    make 
    make install
    cd -
fi


# =================================Install libpng===================================
LIB_VERSION=1.6.35
LIB_NAME=libpng-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}
LIBPNG_ROOT_DIR=${LIB_INSTALL_DIR}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
	if [ ! -d ${LIB_SRC_DIR} ]; then
		if [ -f ${LIB_SRC_TAR_GZ} ]; then
			tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
		else
			wget https://ghproxy.com/https://github.com/glennrp/libpng/archive/refs/tags/v${LIB_VERSION}.tar.gz -O ${LIB_SRC_TAR_GZ}
			tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
		fi
	fi

	cd ${LIB_SRC_DIR}
	#make clean
	./configure  --enable-static --enable-shared=no --prefix=${LIB_INSTALL_DIR} \
		CFLAGS="-I${ZLIB_ROOT_DIR}/include" \
		CPPFLAGS="-I${ZLIB_ROOT_DIR}/include" \
		LDFLAGS="-L${ZLIB_ROOT_DIR}/lib" 
	make 
	make install
	cd -
fi


# =================================Install pixman===================================
LIB_VERSION=0.40.0
LIB_NAME=pixman-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}
PIXMAN_ROOT_DIR=${LIB_INSTALL_DIR}

if [ ! -d ${LIB_INSTALL_DIR} ]; then
    if [ ! -d ${LIB_SRC_DIR} ]; then
        if [ -f ${LIB_SRC_TAR_GZ} ]; then
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        else
            wget https://www.cairographics.org/releases/${LIB_NAME}.tar.gz -O ${LIB_SRC_TAR_GZ}
            tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        fi
    fi

    cd ${LIB_SRC_DIR}
	#make clean
    ./configure --enable-static --enable-shared=no --prefix=${LIB_INSTALL_DIR} PNG_CFLAGS="-I${LIBPNG_ROOT_DIR}/include/libpng16" PNG_LIBS="-L${LIBPNG_ROOT_DIR}/lib -lpng16" 
    make 
    make install
    cd -
fi


# =================================Install bzip2===================================
#LIB_VERSION=1.0.8
#LIB_NAME=bzip2-${LIB_VERSION}
#LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
#LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
#LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
#LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}
#BZIP2_ROOT_DIR=${LIB_INSTALL_DIR}

#if [ ! -d ${LIB_INSTALL_DIR} ]; then
    #if [ ! -d ${LIB_SRC_DIR} ]; then
        #if [ -f ${LIB_SRC_TAR_GZ} ]; then
            #tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        #else
            #wget https://sourceware.org/pub/bzip2/bzip2-${LIB_VERSION}.tar.gz -O ${LIB_SRC_TAR_GZ}
            #tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        #fi
    #fi

    #cd ${LIB_SRC_DIR}
    #make 
    #make install PREFIX=${LIB_INSTALL_DIR}
    #cd -
#fi

# =================================Install freetype===================================
LIB_VERSION=2.12.0
LIB_NAME=freetype-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}
FREETYPE_ROOT_DIR=${LIB_INSTALL_DIR}

#rm -fr ${LIB_INSTALL_DIR}
if [ ! -d ${LIB_INSTALL_DIR} ]; then
	if [ ! -d ${LIB_SRC_DIR} ]; then
		if [ -f ${LIB_SRC_TAR_GZ} ]; then
			tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
		else
			wget https://download.savannah.gnu.org/releases/freetype/${LIB_NAME}.tar.gz -O ${LIB_SRC_TAR_GZ}
			tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
		fi
	fi

	cd ${LIB_SRC_DIR}
	make clean
	./configure --enable-static --enable-shared=no \
		--with-bzip2=no \
		--prefix=${LIB_INSTALL_DIR} \
		LIBPNG_CFLAGS="-I${LIBPNG_ROOT_DIR}/include/libpng16" \
		LIBPNG_LIBS="-L${LIBPNG_ROOT_DIR}/lib -lpng16" \
		ZLIB_CFLAGS="-I${ZLIB_ROOT_DIR}/include" \
		ZLIB_LIBS="-L${ZLIB_ROOT_DIR}/lib -lz" 
	#BZIP2_CFLAGS="-I${BZIP2_ROOT_DIR}/include" BZIP2_LIBS="-L${BZIP2_ROOT_DIR}/lib -lbz2" 
	make 
	make install
	cd -
fi

# =================================Install cairo===================================
LIB_VERSION=1.16.0
LIB_NAME=cairo-${LIB_VERSION}
LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

#rm -fr ${LIB_INSTALL_DIR}
if [ ! -d ${LIB_INSTALL_DIR} ]; then
	if [ ! -d ${LIB_SRC_DIR} ]; then
		if [ -f ${LIB_SRC_TAR_GZ} ]; then
			tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
		else
			wget https://www.cairographics.org/releases/${LIB_NAME}.tar.xz -O ${LIB_SRC_TAR_GZ}
			tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
		fi
	fi

	cd ${LIB_SRC_DIR}
	#make clean
	./configure --enable-static \
		--enable-shared=no \
		--enable-xlib-xcb=no \
		--enable-xcb=no \
		--enable-xcb-shm=no \
		--enable-xlib=no \
		--enable-xlib-xrender=no \
		--enable-fc=no \
		--prefix=${LIB_INSTALL_DIR} \
		PKG_CONFIG_PATH="" \
		CFLAGS="-I${ZLIB_ROOT_DIR}/include" \
		CPPFLAGS="-I${ZLIB_ROOT_DIR}/include" \
		LDFLAGS="-L${ZLIB_ROOT_DIR}/lib" \
		LIBS="-lz" \
		png_REQUIRES="yes" \
		png_CFLAGS="-I${LIBPNG_ROOT_DIR}/include/libpng16" \
		png_LIBS="-L${LIBPNG_ROOT_DIR}/lib -lpng16" \
		FREETYPE_CFLAGS="-I${FREETYPE_ROOT_DIR}/include/freetype2" \
		FREETYPE_LIBS="-L${FREETYPE_ROOT_DIR}/lib -lfreetype" \
		pixman_CFLAGS="-I${PIXMAN_ROOT_DIR}/include/pixman-1" \
		pixman_LIBS="-L${PIXMAN_ROOT_DIR}/lib -lpixman-1" 
	make 
	make install
	cd -
fi

## =================================Install glad===================================
#LIB_VERSION=0.1.36
#LIB_NAME=glad-${LIB_VERSION}
#LIB_SRC_TAR_GZ=${SOURCE_DIR}/${LIB_NAME}.tar.gz 
#LIB_SRC_DIR=${SOURCE_DIR}/${LIB_NAME}
#LIB_BUILD_DIR=${BUILD_DIR}/${LIB_NAME}
#LIB_INSTALL_DIR=${INSTALL_DIR}/${LIB_NAME}

#if [ ! -d ${LIB_INSTALL_DIR} ]; then
    #if [ ! -d ${LIB_SRC_DIR} ]; then
        #if [ -f ${LIB_SRC_TAR_GZ} ]; then
            #tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        #else
            #wget https://github.com/Dav1dde/glad/archive/refs/tags/v${LIB_VERSION}.tar.gz -O ${LIB_SRC_TAR_GZ}
            #tar -vxf ${LIB_SRC_TAR_GZ} -C ${SOURCE_DIR}
        #fi
    #fi

    #mkdir -p ${LIB_BUILD_DIR}
    #cmake -B ${LIB_BUILD_DIR} -S ${LIB_SRC_DIR} -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_DIR}
    #cmake --build ${LIB_BUILD_DIR}
    #mkdir -p ${LIB_INSTALL_DIR}
    #mkdir -p ${LIB_INSTALL_DIR}/lib
    #cp -fr ${LIB_BUILD_DIR}/include ${LIB_INSTALL_DIR}
    #cp -fr ${LIB_BUILD_DIR}/libglad.a ${LIB_INSTALL_DIR}/lib
#fi
